<?php

namespace Kunfeng\Dify\Enum;

/**
 * 文件类型枚举
 */
class FileType
{
    public const DOCUMENT = 'document';
    public const IMAGE = 'image';
    public const AUDIO = 'audio';
    public const VIDEO = 'video';

    /**
     * 获取对应的 MIME 类型
     */
    public static function getMimeType(string $type): string
    {
        switch ($type) {
            case self::DOCUMENT:
                return 'application/octet-stream';
            case self::IMAGE:
                return 'image/*';
            case self::AUDIO:
                return 'audio/*';
            case self::VIDEO:
                return 'video/*';
            default:
                return 'application/octet-stream';
        }
    }

    /**
     * 根据文件扩展名获取文件类型
     */
    public static function fromExtension(string $extension): ?string
    {
        $extension = strtolower($extension);
        
        switch ($extension) {
            case 'pdf':
            case 'doc':
            case 'docx':
            case 'txt':
            case 'md':
                return self::DOCUMENT;
            case 'jpg':
            case 'jpeg':
            case 'png':
            case 'gif':
            case 'bmp':
            case 'webp':
                return self::IMAGE;
            case 'mp3':
            case 'wav':
            case 'ogg':
            case 'm4a':
            case 'aac':
                return self::AUDIO;
            case 'mp4':
            case 'avi':
            case 'mov':
            case 'wmv':
            case 'flv':
                return self::VIDEO;
            default:
                return null;
        }
    }

    /**
     * 获取所有类型
     */
    public static function getAll(): array
    {
        return [
            self::DOCUMENT,
            self::IMAGE,
            self::AUDIO,
            self::VIDEO,
        ];
    }
}